﻿using System;
using System.Collections.Generic;
using System.Text;

//保存订单信息，订单的日期，交易金额,订单号
namespace Homework8_Order
{
    [Serializable]
    public class Order
    {
        public int OrderID { get; set; }//订单号，查询条件1
        public string Name { get; set; }//顾客名称，查询条件3
        public int AmountSum { get; set; } = 0;//交易总额
        public List<OrderItem> orderList { get; set; } = new List<OrderItem>();//用于储存订单明细

        public Order()
        {
        }

        public Order(int ID, string CName)
        {
            OrderID = ID;
            Name = CName;
        }

        //通过订单号的唯一性判断是否重复添加订单
        public override bool Equals(object obj)
        {
            Order o = obj as Order;
            return o != null && o.OrderID == OrderID;
        }

        //添加订单明细
        public void addOrderItem(OrderItem itm)
        {
            orderList.Add(itm);
            Console.WriteLine("添加成功");
            AmountSum = AmountSum + itm.TotalPrice;
        }

        //逐个输出订单明细
        public override string ToString()
        {
            Console.WriteLine("订单号：" + OrderID + ' ' + "总金额：" + AmountSum);
            foreach (OrderItem a in orderList)
            {
                Console.WriteLine("订单号：" + OrderID + ' ' + "商品名称：" + a.GoodsName + ' ' + "客户名：" + Name + ' ' + "商品单价" + a.Price + ' ' + "购买数量：" + a.Amount + ' ' + "总价：" + a.TotalPrice + ' ' + "交易时间：" + a.Time);
            }

            return "成功输出";
        }
    }
}
